﻿/* $RCSFile: FullInterview.ascx.cs $
 * Copyright (C) Addon Nice Technologies 2010
 * $Source: ?/Addon Nice/AddonNice/AddonNice.LeadProspection/PageModules/Interview/FullInterview.ascx.cs $
 * $log$
 * Revision 24 2010/08/09 11:16:26  christian.surieux
 *   Added Log comment to all .ascx .aspx .master files
 * Revision 11 2010/08/09 10:18:24  christian.surieux
 *   Added Log comment to all cs files
 */

using System;
using System.Globalization;
using System.Diagnostics;
using System.IO;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Web;
using System.Web.Configuration;
using AddonNice.Configuration.Settings;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Collections.Generic;
using System.Web.Security;
using System.Xml;
using System.Configuration;

using AddonNice;
using AddonNice.UI;
using AddonNice.UI.WebControls;
using AddonNice.Configuration;
using AddonNice.Security;
using AddonNice.UI.DataTypes;
using AddonNice.Helpers;
using AddonNice.Diagnostics;
using AddonNice.Settings;
using AddonNice.Core;

using AddonNice.CRMWrapper;
using AddonNice.CRMWrapper.Design;

using AddonNice.LeadProspection.Settings;

using Telerik.Web.UI;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.PageModules.Interview
{

    #region Local TraceSwitch 
	
    public class FullInterviewTrace : ADNTraceSwitch
	{
		static public ADNTraceSwitch	Sw	=	new ADNTraceSwitch("FullInterviewTrace","Special Trace Switch for FullInterview");
	}
	#endregion Local TraceSwitch 

    /// <summary>
    /// Initializer class for FullInterview 
    /// </summary>
    public class FullInterviewSI : PortalCRMModuleControlSI
    {
        public FullInterviewSI(ModuleSettingsDictionary bSettings,ISettingsOwner pm) : base()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]FullInterviewSI Ctor BEG.",ModuleTraceSwitch.Sw.Info);
            InitSettings(bSettings,pm);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]FullInterviewSI Ctor END.",ModuleTraceSwitch.Sw.Info);
        }
 
        public override void InitSettings(ModuleSettingsDictionary bSettings,ISettingsOwner pm)
        {             
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]FullInterviewSI InitSettings BEG.",ModuleTraceSwitch.Sw.Info);
            
            base.InitSettings(bSettings,pm);

            string extgrp                           =   pm.ExtendedResourcesGroup;

            SettingItemSpecial Attached2Entity      =	new SettingItemSpecial(PStr.Attached2Entity,new BooleanDataType());
			Attached2Entity.Order			        =	10;
            Attached2Entity.Value			        =	StStr.strTrue;
            Attached2Entity.ResourceFile            =   PStr.ResourceFile;
            Attached2Entity.ResourceItem            =   PStr.ResourceItem;
			Attached2Entity.ExtendedGroupName       =   extgrp;
			Attached2Entity.Description		        =	"Attached to an entity";
            Attached2Entity.EnglishName		        =	"Check if this module is attached to another form entity";
			bSettings.AddSetting(Attached2Entity);

            ArrayList Al                            =   new ArrayList();
            Al.Add(new SettingStringOption(CrmStr.phonecall,CrmStr.phonecall));
            Al.Add(new SettingStringOption(CrmStr.appointment,CrmStr.appointment));
            Al.Add(new SettingStringOption(CrmStr.task,CrmStr.task));
            Al.Add(new SettingStringOption(CrmStr.account,CrmStr.account));
            Al.Add(new SettingStringOption(CrmStr.contact,CrmStr.contact));
            Al.Add(new SettingStringOption(CrmStr.lead,CrmStr.lead));

            SettingItemSpecial EntityName           =	new SettingItemSpecial(PStr.EntityName,new CustomListDataType(Al,StStr.smName,StStr.smVal));
			EntityName.Order			            =	20;
            EntityName.Value			            =	CrmStr.phonecall;
            EntityName.ResourceFile                 =   PStr.ResourceFile;
            EntityName.ResourceItem                 =   PStr.ResourceItem;
			EntityName.ExtendedGroupName            =   extgrp;
			EntityName.Description		            =	"Entity name";
            EntityName.EnglishName		            =	"If attached to another entity, select the entity";
			bSettings.AddSetting(EntityName);

            SettingItemSpecial InterviewLen         =	new SettingItemSpecial(PStr.InterviewLen,new IntegerDataType());
			InterviewLen.Order			            =	30;
            InterviewLen.Value			            =	"2000";
            InterviewLen.ResourceFile               =   PStr.ResourceFile;
            InterviewLen.ResourceItem               =   PStr.ResourceItem;
			InterviewLen.ExtendedGroupName          =   extgrp;
			InterviewLen.Description		        =	"Max interview text length";
            InterviewLen.EnglishName		        =	"Max interview text length";
			bSettings.AddSetting(InterviewLen);

            SettingItemSpecial FixedCampaign        =   new SettingItemSpecial(PStr.FixedCampaign,new BooleanDataType());
            FixedCampaign.Required                  =   false;
            FixedCampaign.ResourceFile              =   PStr.ResourceFile;
            FixedCampaign.ResourceItem              =   PStr.ResourceItem;
            FixedCampaign.Value                     =   StStr.strFalse;
            FixedCampaign.Order                     =   40;
            FixedCampaign.ExtendedGroupName         =   extgrp;
            FixedCampaign.EnglishName               =   "Fixed Campaign";
            FixedCampaign.Description               =   "When checked, module will use the campain selected in next setting";
            bSettings.AddSetting(FixedCampaign);

            //Fixed campaign
            WSListDataType defCampaign              =   new WSListDataType(CrmStr.campaign,StStr.smName, "ID");
            SettingItemSpecial Campaign             =   new SettingItemSpecial(PStr.MCampaign,defCampaign);
            Campaign.EnglishName                    =   "Campaign";
            Campaign.Order                          =   50;
            Campaign.ResourceFile                   =   PStr.ResourceFile;
            Campaign.ResourceItem                   =   PStr.ResourceItem;
            Campaign.ExtendedGroupName              =   extgrp;
            Campaign.Description                    =   "Select a default campaign to associate with this Rating";
            Campaign.SettingItemsEvent              +=  new SettingItemsEventHandler(Campaign_SettingItemsEvent);
            bSettings.AddSetting(Campaign);

            SettingItemSpecial CacheDelay        =   new SettingItemSpecial(PStr.CacheDelay,new IntegerDataType());
            CacheDelay.Required                  =   false;
            CacheDelay.ResourceFile              =   PStr.ResourceFile;
            CacheDelay.ResourceItem              =   PStr.ResourceItem;
            CacheDelay.Value                     =   "30";
            CacheDelay.Order                     =   60;
            CacheDelay.ExtendedGroupName         =   extgrp;
            CacheDelay.EnglishName               =   "Cache delay";
            CacheDelay.Description               =   "Delay in minutes for the project items elements";
            bSettings.AddSetting(CacheDelay);

            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]FullInterviewSI InitSettings END.",ModuleTraceSwitch.Sw.Info);
        }
        
        /// <summary>
        /// Used to set the good display value in Campaign when loaded from DB
        /// </summary>
        void Campaign_SettingItemsEvent(object sender, SettingItemsEventArgs e)
        {
            if ( e.EventType != SettingItemsEventType.Loaded )
                return;
            if ( FullInterviewTrace.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterviewSI Campaign_SettingItemsEvent Guid: {0}", e.Data),FullInterviewTrace.Sw.Info);
            Guid custId                     =   new Guid((string)e.Data);
            if ( custId == Guid.Empty )
                return;
            ADNDynCampaign dynac            =   DynEntity.GetFromCache<ADNDynCampaign>(CrmStr.campaign,Wrapper,new ResetWrapperHandler(ResetWrapper),custId);
            WSListDataType defCampaign      =   (WSListDataType )((SettingItem)sender).DataType;
            defCampaign.DisplayTextValue    =   dynac.name;
            if ( FullInterviewTrace.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterviewSI ModuleOwner_SettingItemsEvent END name: {0}", dynac.name),FullInterviewTrace.Sw.Info);
        }
    }

    public partial class FullInterview : PortalCRMModuleControl
    {

		#region Global Implementation

        public override Guid GuidID 
		{
			get
			{
				return new Guid("{B52A61AC-7009-4b1f-9193-B3B2D6D1CF4F}");
			}
		}

		#endregion Global Implementation

        #region Ctor

        
        InterviewUtil _Util  =   null;
        InterviewUtil Util
        {
            get
            {
                if ( _Util == null )
                    _Util                           =   new InterviewUtil(Wrapper,ResetWrapper,(interviewID == Guid.Empty) ? dynI.interviewid:interviewID,Settings[PStr.CacheDelay].ToInt());
                return _Util;
            }
        }


        string _EntityName  =   string.Empty;
        public override string EntityName
        {
            get
            {
                if ( _EntityName != string.Empty )
                    return _EntityName;
                if ( Settings[PStr.Attached2Entity].ToBool() )
                    _EntityName     =   Settings[PStr.EntityName].Value;
                else _EntityName    =   base.EntityName;
                return _EntityName;
            }
        }

        Guid interviewID
        {
            get
            {
                object ob   =   ViewState[PStr.interviewid];
                if ( ob != null )
                    return (Guid)ob;
                return Guid.Empty;
            }
            set
            {
                ViewState[PStr.interviewid] =   value;
            }
        }
       
        ADNDynInterview _dynI   =   null;
        ADNDynInterview dynI
        {
            get
            {
 			    if (FullInterviewTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview dynI GET BEG dynI null: {0}, IsUnderCRM: {1}, IsPostBack: {2}",_dynI == null,IsUnderCRM,IsPostBack),FullInterviewTrace.Sw.Info);
                if ( _dynI != null )
                    return _dynI;
                if ( IsUnderCRM && !IsInEntityCreationMode )
                {
		            if (FullInterviewTrace.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview dynI GET EntityName: {0}",EntityName),FullInterviewTrace.Sw.Info);
                    switch ( EntityName )
                    {
                        case CrmStr.phonecall:
                        ADNDynPhoneInterview dynP   =   DynEntity.GetFromCache<ADNDynPhoneInterview>(CrmStr.phonecall,Wrapper,ResetWrapper,EntityID);
                        if ( dynP.Retrieved )
                            interviewID             =   dynP.interviewid;
                        break;
                        default:
                        DynEntity dynE              =   DynEntity.GetFromCache<DynEntity>(EntityName,Wrapper,ResetWrapper,EntityID);
                        if ( dynE.Retrieved )
                        {
                            if ( dynE.ContainsKey(PStr.interviewid) )
                                interviewID         =   dynE.LookupPropertyValue(PStr.interviewid);
                        }
                        break;
                    }
                    _dynI                           =   DynEntity.GetFromCache<ADNDynInterview>(PStr.interview,Wrapper,ResetWrapper,interviewID);
		            if (FullInterviewTrace.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview dynI GET _dynI.Retrieved: {0}",_dynI.Retrieved),FullInterviewTrace.Sw.Info);
                }
                else if ( interviewID != Guid.Empty )
                {
                    _dynI                           =   DynEntity.GetFromCache<ADNDynInterview>(PStr.interview,Wrapper,ResetWrapper,interviewID);
		            if (FullInterviewTrace.Sw.TraceVerbose)
                        Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview dynI GET _dynI.Retrieved: {0}",_dynI.Retrieved),FullInterviewTrace.Sw.Info);
                }
                return _dynI;
            }
        }

        /// <summary>
		/// Ctor Set the properties of the module
		/// </summary>
        public FullInterview()
        {
			if (ModuleTraceSwitch.Sw.TraceVerbose || FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview Ctor enter at: {0}", DateTime.UtcNow), (ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info :FullInterviewTrace.Sw.Info);
        }

       public override string ExtendedResourcesGroup 
		{
            get
            {
       			const string extgrp                     =   "FULLINTERVIEW";
                return extgrp;
            }
		}

        public override void InitPortalModuleControl(ModuleSettingsDictionary bSettings)
        {
            PortalModuleInitializer =   new FullInterviewSI(bSettings,this);
        }

        #endregion Ctor

        protected void Page_Load(object sender, EventArgs e)
        {
			if (ModuleTraceSwitch.Sw.TraceVerbose || FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview Page_Load BEG IsPostBack: {0}, IsInEntityCreationMode : {1}",IsPostBack,IsInEntityCreationMode), (ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info :FullInterviewTrace.Sw.Info);
            if ( ! IsPostBack )
            {
                // Fill the various PickList combo
                CbContactRole.DataTextField                 =   StStr.smName;
                CbContactRole.DataValueField                =   StStr.smVal;
                CbContactRole.DataSource                    =   Wrapper.Util.ListFromPickList(PStr.contactrole,PStr.interview);
                CbContactRole.DataBind();

                CbInfoSerdao.DataTextField                  =   StStr.smName;
                CbInfoSerdao.DataValueField                 =   StStr.smVal;
                CbInfoSerdao.DataSource                     =   Wrapper.Util.ListFromPickList(PStr.additionnalinfo,PStr.interview);
                CbInfoSerdao.DataBind();

                CbProjectRating.DataTextField               =   StStr.smName;
                CbProjectRating.DataValueField              =   StStr.smVal;
                CbProjectRating.DataSource                  =   Wrapper.Util.ListFromPickList(PStr.projectprobability,PStr.interview);
                CbProjectRating.DataBind();

                CbProjectStatus.DataTextField               =   StStr.smName;
                CbProjectStatus.DataValueField              =   StStr.smVal;
                CbProjectStatus.DataSource                  =   Wrapper.Util.ListFromPickList(PStr.projectstatus,PStr.interview);
                CbProjectStatus.DataBind();

                RadEditContent.MaxHtmlLength                =   Settings[PStr.InterviewLen].ToInt();

                // Fill the campaign combo
                Guid CampaignId                             =    Settings[PStr.MCampaign].ToGuid();
                if ( FullInterviewTrace.Sw.TraceVerbose )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterviewTrace Page_Load  CampaignId: {0}.",CampaignId),FullInterviewTrace.Sw.Info);
                // When attached to Crm Form, we extract the interviewid from the corresponding entity
                if ( IsUnderCRM )
                {
                    if ( (dynI != null ) && dynI.Retrieved )
                    {
                        TbSubject.Text                      =   dynI.subject;
                        RadComboBoxItem it                  =   CbContactRole.Items.FindItemByValue(dynI.contactrole.ToString());
                        if ( it != null )
                            it.Selected                     =   true;
                        it                                  =   CbInfoSerdao.Items.FindItemByValue(dynI.additionnalinfo.ToString());
                        if ( it != null )
                            it.Selected                     =   true;

                        it                                  =   CbProjectRating.Items.FindItemByValue(dynI.projectprobability.ToString());
                        if ( it != null )
                            it.Selected                     =   true;

                        it                                  =   CbProjectStatus.Items.FindItemByValue(dynI.projectstatus.ToString());
                        if ( it != null )
                            it.Selected                     =   true;
                        ChkOpenRequest.Checked              =   dynI.openrequest;
                        ChkExpertCallback.Checked           =   dynI.expertrecall;
                        TbGroupMembership.Text              =   dynI.groupmembership;
                        TbCallerComment.Text                =   dynI.callercomments;
                        RadEditContent.Content              =   dynI.content;
                        TbContactName.Text                  =   dynI.contactName;
                        TbContactName.ReadOnly              =   true;
                        if ( dynI.contactid != Guid.Empty )
                        {
                            ADNDynContact dynC              =   DynEntity.GetFromCache<ADNDynContact>(CrmStr.contact,Wrapper,ResetWrapper,dynI.contactid);
                            if ( dynC.Retrieved )
                            {
                                TbContactMainPhone.Text     =   dynC.telephone1;
                                TbContactEMail.Text         =   dynC.emailaddress1;
                            }
                        }
                        CampaignId                          =   dynI.campaignid;
                    }
                }
                 if ( CampaignId != Guid.Empty )
                {
                    ADNDynCampaign dnc                      =   DynEntity.GetFromCache<ADNDynCampaign>(CrmStr.campaign,Wrapper,ResetWrapper,CampaignId);
                    if ( dnc != null )
                    {
                        RadComboBoxItem itc                 =    new RadComboBoxItem(dnc.name,CampaignId.ToString());
                        itc.Selected                        =   true;
                        CbCampaign.Items.Add(itc);
                        CbCampaign.DataBind();
                        if (FullInterviewTrace.Sw.TraceVerbose)
                            Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterviewTrace Page_Load Campaign: {0}.",dnc.name),FullInterviewTrace.Sw.Info);
                    }
                }

                if ( Settings[PStr.FixedCampaign].ToBool() )
                    CbCampaign.Enabled  =   false;
               EditTable.DataBind();
            }
        }


        void EditTable_NeedDataSource(object sender,SettingsTableEventArgs e)
        {
			if (FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_NeedDataSource BEG Util.EntityID: {0}",Util.EntityID),FullInterviewTrace.Sw.Info);
            if ( Util.EntityID == Guid.Empty )
            {
			    if (FullInterviewTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_NeedDataSource interviewID: {0}",interviewID),FullInterviewTrace.Sw.Info);
                if ( ( interviewID != Guid.Empty ) || dynI != null )
                    Util.EntityID   =   interviewID;
			    if (FullInterviewTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_NeedDataSource dynI != null: {0}",dynI != null),FullInterviewTrace.Sw.Info);
            }
            e.CurrentTable.DataSource         =   Util.cSettings;
			if (FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine("[V]FullInterview EditTable_NeedDataSource END.",FullInterviewTrace.Sw.Info);
        }

        void  FullInterview_ADNUpdateModule(object sender, ModuleEventArgs e)
        {
            // Only Update if Input Data is Valid
            if ( FullInterviewTrace.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview FullInterview_ADNUpdateModule BEG ModuleID: {0}", ModuleID),FullInterviewTrace.Sw.Info);
            bool shouldCreate                   =   false;
            if ( dynI == null ) 
            {
                shouldCreate                    =   true;
                _dynI                           =   new ADNDynInterview(Wrapper,TbSubject.Text.Trim());
            }
            try
            {
                dynI.contactrole                =   int.Parse(CbContactRole.SelectedValue);
                dynI.additionnalinfo            =   int.Parse(CbInfoSerdao.SelectedValue);
                dynI.projectprobability         =   int.Parse(CbProjectRating.SelectedValue);
                dynI.projectstatus              =   int.Parse(CbProjectStatus.SelectedValue);
                dynI.openrequest                =   ChkOpenRequest.Checked;
                dynI.expertrecall               =   ChkExpertCallback.Checked;
                dynI.groupmembership            =   TbGroupMembership.Text.Trim();
                dynI.callercomments             =   TbCallerComment.Text.Trim();
                dynI.content                    =   RadEditContent.Content;
                Guid CampaignId                 =    Settings[PStr.MCampaign].ToGuid();
                if ( Settings[PStr.FixedCampaign].ToBool() && ( CampaignId != Guid.Empty) && ( dynI.campaignid == Guid.Empty ) )
                    dynI.campaignid             =   CampaignId;
                if ( shouldCreate )
                    interviewID                 =   dynI.Create();
                else dynI.Update();
                if ( dynI.contactid != Guid.Empty )
                {
                    ADNDynContact dynC          =   DynEntity.GetFromCache<ADNDynContact>(CrmStr.contact,Wrapper,ResetWrapper,dynI.contactid);
                    bool shouldUpd              =   false;
                    if ( dynC.Retrieved )
                    {
                        string newPhone         =   TbContactMainPhone.Text.Trim();
                        if (newPhone != dynC.telephone1 )
                        {
                            dynC.telephone1     =   newPhone;
                            shouldUpd           =   true;
                        }
                        string newMail          =    TbContactEMail.Text.Trim();
                        if ( dynC.emailaddress1 != newMail )
                        {
                            dynC.emailaddress1  =  newMail;
                            shouldUpd           =   true;
                        }
                        if ( shouldUpd )
                            dynC.Update();
                    }
                }
            }
            catch(Exception ex)
            {
                if ( FullInterviewTrace.Sw.TraceError )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]FullInterview FullInterview_ADNUpdateModule ex: {0}", ex),FullInterviewTrace.Sw.Info);
                throw;
            }
            try
            {
                // Update settings in the database
                EditTable.UpdateControls();
            }
            catch(Exception ex)
            {
                if ( FullInterviewTrace.Sw.TraceError )
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]FullInterview FullInterview_ADNUpdateModule Editatble.UpdateControls ex: {0}", ex),FullInterviewTrace.Sw.Info);
                throw;
            }
            if ( FullInterviewTrace.Sw.TraceVerbose )
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview FullInterview_ADNUpdateModule END ModuleID: {0}", ModuleID),FullInterviewTrace.Sw.Info);
        }

        void EditTable_UpdateControl(object sender,SettingsTableItemEventArgs e)
        {
			if (FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_UpdateControl BEG TableType: {0}",e.SettingType),FullInterviewTrace.Sw.Info);
            string key                  =   e.CurrentItem.EnglishName; // beware don't take editcontrol ID because it is upper case
            string val                  =   e.CurrentItem.Value;
            
            ADNDynProjectItemValue piv  =   null;
            if ( Util.PValuesList.ContainsKey(key) )
            {
			    if (FullInterviewTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_UpdateControl piv found key: {0}",key),FullInterviewTrace.Sw.Info);
                piv                     =   Util.PValuesList[key];
                piv.value               =   val;
                piv.Update();
			    if (FullInterviewTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_UpdateControl piv updated val: {0}",val),FullInterviewTrace.Sw.Info);
            }
            else
            {
			    if (FullInterviewTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_UpdateControl creating piv for key: {0}",key),FullInterviewTrace.Sw.Info);
                piv                     =   new ADNDynProjectItemValue(Wrapper,key);
                // get the project item with same key
                ADNDynProjectItem pi    =   Util.PItemLst[key];
                piv.itemid              =   pi.projectitemid;
                piv.value               =   val;
                piv.interviewid         =   Util.EntityID;
                piv.Create();
			    if (FullInterviewTrace.Sw.TraceVerbose)
                    Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_UpdateControl piv created val: {0}",val),FullInterviewTrace.Sw.Info);
            }
			if (FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]FullInterview EditTable_UpdateControl END key: {0}",key),FullInterviewTrace.Sw.Info);
        }

        #region Std overrides 

        /// <summary>
        /// Triggered from Page.OnPreInit
        /// We must set the Add button before buttons are initialized by base method
        public override void Page_PreInit(object sender, EventArgs e)
        {
			if (ModuleTraceSwitch.Sw.TraceVerbose || FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine("[V]FullInterview Page_PreInit BEG.",(ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info :FullInterviewTrace.Sw.Info);
            base.Page_PreInit(sender, e);
            string strcult                  =   Helpers.LocalizeHelper.GetCurrentNeutralCultureName();
            updateBtn.SkinID                =   "Update_"+strcult;
            EditTable.NeedDataSource        +=  new SettingsTableEventHandler(EditTable_NeedDataSource);
 			if (ModuleTraceSwitch.Sw.TraceVerbose || FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine("[V]FullInterview Page_PreInit END.",(ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info :FullInterviewTrace.Sw.Info);
       }

		override protected void OnInit(EventArgs e)
		{
			if (ModuleTraceSwitch.Sw.TraceVerbose || FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine("[V]FullInterview OnInit BEG.",(ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info :FullInterviewTrace.Sw.Info);
			InitializeComponent();
			base.OnInit(e);
			if (ModuleTraceSwitch.Sw.TraceVerbose || FullInterviewTrace.Sw.TraceVerbose)
                Trace2.WriteLine("[V]FullInterview OnInit END.",(ModuleTraceSwitch.Sw.TraceVerbose ) ? ModuleTraceSwitch.Sw.Info :FullInterviewTrace.Sw.Info);
		}

		private void InitializeComponent()
		{
            Load                            +=  new EventHandler(Page_Load);
            EditTable.UpdateControl         +=  new UpdateControlEventHandler(EditTable_UpdateControl);
            ADNUpdateModule                 +=  new PortalModuleEventHandler(FullInterview_ADNUpdateModule);
 		}


        #endregion
    }
}